from selenium import webdriver
from pprint import pprint

# 打开浏览器, 请求目标网址
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

# 操作cookie
# 获取所有cookie
print(driver.get_cookies())

# 返回特定name的cookie信息
print(driver.get_cookie('BA_HECTOR'))

# 添加cookie必须有name和value
dict1 = {'name': 'he', 'value': '123'}
driver.add_cookie(dict1)
print(driver.get_cookie('he'))

# 删除特定部分的cookie
driver.delete_cookie('he')
print(driver.get_cookie('he'))

# 删除所有的cookies
driver.delete_all_cookies()
print(driver.get_cookies())
# 退出浏览器
driver.quit()
